# -*- coding:utf-8 -*-
"""
author:tuhou
time:2022/12/4 22:08 
思路：
"""
import requests
import execjs


with open("yien.js", "r") as f:
    js_read = f.read()

js = execjs.compile(js_read)


def get_encrypt_content(year, method):
    """
    根据年份和方法来进行数据的获取，每个方法需要的参数不一样
    年度票房：BoxOffice_GetYearInfoData
    全球票房：BoxOffice_GetAllInfoData   (wId, MethodName)
    历史票房：BoxOffice_GetHistoryList   (MethodName)
    @param year:
    @param method:
    @return:
    """
    url = "https://www.endata.com.cn/API/GetData.ashx"
    data = {
        "year": year,
        "MethodName": method
    }
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
    }
    response = requests.post(url, headers=headers, data=data)
    return response.text


if __name__ == '__main__':
    encrypt_content = get_encrypt_content(2022, "BoxOffice_GetYearInfoData")
    print(js.call("get_content", encrypt_content))
